import Taro from '@tarojs/taro';
import {Image, View} from '@tarojs/components';
import {connect} from "@tarojs/redux";
import {AtInput} from 'taro-ui';
import {appConfig, request, unite} from '../../../utils/index';
import {actionCreator} from "../../../store/actions";
import Shop from "../../../asset/images/add_shop.png";
import './addCourse.scss';

class AddCourse extends Taro.Component {
    config = {
        navigationBarTitleText: '添加课程',
        backgroundColor: '#fff',
    };

    state = {
        dataList: [],
    };

    componentDidShow() {
        this.init();
    }

    init = () => {
        const params = {
            url: '/wx/coach/myDispachClassInfo',
            data:{}
        };
        request(params).then(res => {
            Taro.stopPullDownRefresh(); //停止当前页面下拉刷新
            if (res) {
                if(res.code == 200) {
                    if (res && res.data) {
                        this.setState({
                            dataList: res.data,
                        })
                    }
                }
            }
        })
    };

    //选择课程
    selectKc = (item) => {
        const {getGainCourse} = this.props;
        getGainCourse({
            dispatchId: item.dispatchId,
            avatar: item.avatar,
            className: item.className,
            classScaleName: item.classScaleName,
            labelNames: item.labelNames,
        });
        Taro.navigateBack({
            delta: 1
        });
        // Taro.navigateBack({url: '../issuePage/issuePage?id=' + item.classRefId+'&avatar='+item.avatar+'&className='+item.className+'&classScaleName='+item.classScaleName+'&labelNames='+item.labelNames})
    };

    render() {
        const {dataList} = this.state;
        return (
            <View className="page">
                <View className="course-list-wrap">
                    {dataList.map((item, index) => (
                        <View key={index}>
                            {item.dispatchClassDetails.map((value, is) => (
                                <View className="keep-content-list-item" key={is} onClick={this.selectKc.bind(this, value)}>
                                    <Image className="list-img" src={value.avatar}/>
                                    <View className="list-centent-left-wrap ">
                                        <View className="list-centent">
                                            <View className="name">{value.className}</View>
                                            <View className="timer">{value.classBeginTime +'-'+ value.classEndTime}</View>
                                            <View className="type flex-l">
                                                {/*<View className="list-top-left flex-center text-overflow">{value.reservedInfo}</View>*/}
                                                {value.labelNames.map((items, indexs) => (
                                                    <View className="kepp-gg flex-center" key={indexs}>{items}</View>
                                                ))}
                                            </View>
                                        </View>
                                        <View className="list-right-bt" style="background: rgba(0,0,0,0);"></View>
                                    </View>
                                </View>
                            ))}
                        </View>
                    ))}
                </View>
            </View>
        )
    }
}

const mapStateToProps = state => {
    let {userToken, map, gainCourse} = state;
    return {
        userToken,
        map,
        gainCourse
    }
};

const mapDispatchToProps = {
    getbackPage: actionCreator.getbackPage,
    getGainCourse: actionCreator.getGainCourse,
};

export default connect(mapStateToProps, mapDispatchToProps)(AddCourse);



